﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

// 各个状态的驱动类
public class StateMachine
{
    protected State _curState;

    public void ChangeState(State newState, bool fouceChange = false)
    {
        if (fouceChange == false && _curState == newState) { return; }

        //Debug.LogError((newState as HumanState).SType + "," + Time.frameCount);
        // 退出当前状态
        if (_curState != null
            && _curState.ExitCallback != null)
        {
            _curState.ExitCallback();
        }
        // 切换
        _curState = newState;
        // 进入新状态
        if (_curState != null
            && _curState.EnterCallback != null)
        {
            _curState.EnterCallback();
        }
    }
    // 悄悄的切换状态，不触发enter、exit事件
    public void ChangeStateSilence(State newState)
    {
        _curState = newState;
    }

    public void Loop()
    {
        if (_curState != null
            && _curState.LoopCallback != null)
        {
            _curState.LoopCallback();
        }
    }
}

public class State
{
    public Action EnterCallback;
    public Action LoopCallback;
    public Action ExitCallback;
}
